package com.aggregate.pay.yufu.cpos.support.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.aggregate.pay.yufu.cpos.bean.IndividualMerchantAddData;
import com.aggregate.pay.yufu.cpos.bean.IndividualMerchantAddResult;
import com.aggregate.pay.yufu.cpos.bean.IndividualMerchantPayService;
import com.aggregate.pay.yufu.cpos.bean.IndividualMerchantQualificationInfo;
import com.aggregate.pay.yufu.cpos.support.AbstractClient;
import com.aggregate.pay.yufu.cpos.support.Factory;

/**
 * 进件接口（个人版）
 * @author Moyq5
 * @date 2017年9月4日
 */
public class IndividualMerchantAdd extends AbstractClient<IndividualMerchantAddData, IndividualMerchantAddResult> {

	@Override
	protected String getServerPath() {
		return Factory.getConfig().getServerPath() + "IndividualMerchantAddAction.json";
	}

	@Override
	protected Class<IndividualMerchantAddResult> getResultClass() {
		return IndividualMerchantAddResult.class;
	}

	@Override
	protected Map<String, Object> convertToMap(IndividualMerchantAddData data) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		
        //请求参数start
		if (null != data.getCustomerId()) {
			params.put("customerId", data.getCustomerId());
		}
		params.put("expanderCd", Factory.getConfig().getExpanderCd());
		params.put("merchantName", data.getMerchantName());
		params.put("merchantShortName", data.getMerchantShortName());
		params.put("merchantType", "" + data.getMerchantType());
		params.put("merchantLevel", "" + data.getMerchantLevel());
		params.put("parentCustomerId", data.getParentCustomerId());
		params.put("openType", "1");
		params.put("gszcName", "工商注册名");
		params.put("businessModel", data.getBusinessModel());
		params.put("emergencyTelephone", data.getEmergencyTelephone());
		params.put("contacorId", data.getContacorId());
		
	
		IndividualMerchantQualificationInfo qualificationInfos = data.getQualificationInfos();
    	Map<String,Object> p01 = new HashMap<String, Object>();
		p01.put("legalIdName", qualificationInfos.getLegalIdName());
		p01.put("legalIdNumber", qualificationInfos.getLegalIdNumber());
		p01.put("legalIdExpiredTime", qualificationInfos.getLegalIdExpiredTime());		
		p01.put("legalIdInfo", qualificationInfos.getLegalIdInfo());
		p01.put("filename", qualificationInfos.getFilename());
		
		params.put("qualificationInfos", p01);
		params.put("manageOrgId", data.getManageOrgId());
		params.put("merchantAddr", data.getMerchantAddr());
		params.put("province", data.getProvince());
		params.put("city", data.getCity());
		params.put("county", data.getCounty());
		params.put("accountType", "" + data.getAccountType());
		params.put("account", data.getAccount());//
		params.put("accountName", data.getAccountName());
		params.put("banckCode", data.getBankCode());
		params.put("bankName", data.getBankName());
		params.put("openBranch", data.getOpenBranch());
		params.put("merchantConsacts", data.getMerchantContacts());
		params.put("telephone", data.getTelephone());
		params.put("payChennel", data.getPayChennel());
		params.put("tradeType", data.getTradeType());
		params.put("businessModel", data.getBusinessModel());
		params.put("repaidPerson", data.getRepaidPerson());
		params.put("repaidRate", data.getRepaidRate());
		params.put("minAmount", data.getMinAmount());
		params.put("poundage", data.getPoundage());
		params.put("minRepaidAmount", data.getMinRepaidAmount());
		
		List<Map<String,Object>> payServices = new ArrayList<Map<String,Object>>();
		List<IndividualMerchantPayService> payServicez = data.getPayServices();
		if (null != payServicez) {
			for (IndividualMerchantPayService p: payServicez) {
				Map<String,Object> p1 = new HashMap<String, Object>();		
				p1.put("payService", p.getPayService().getValue());
				p1.put("isOpen", p.getIsOpen() == true ? "Y":"N");
				p1.put("scale", p.getScale());
				p1.put("countRole", p.getCountRole());
				p1.put("returns",null == p.getReturns()? null:(p.getReturns() == true?"是": "否"));
				p1.put("servicePhone", p.getServicePhone());
				payServices.add(p1);
			}
		}
		params.put("payServices", payServices);
		//请求参数end
		
		return params;
		
	}

}
